package com.steve.rocketmq;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * @Author: STEVE
 * @Description: 延迟消息生产者
 * @since: 2025-07-17
 */
@Component
public class DelayMessageProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 发送延迟消息
     *
     * @param topic      主题
     * @param message    消息内容
     * @param delayLevel 延迟级别 1-18
     */
    public void sendDelayMessage(String topic, String message, int delayLevel) {
        rocketMQTemplate.syncSend(topic,
                MessageBuilder.withPayload(message).build(),
                3000,   // 发送超时时间
                delayLevel);
        System.out.println("发送延迟消息：" + message + "，延迟级别：" + delayLevel);
    }

}
